'use strict'

process.chdir(__dirname)

const Titbit = require('titbit')
const {Resource} = require('titbit-toolkit')

const app = new Titbit({
  debug: true,
  globalLog: true
})

let rse = new Resource({
  routePath: '/*',
  staticPath: './dns',
})

app.pre(async (ctx, next) => {
  let host = ctx.headers.host
  if (host.indexOf('www.') === 0) {
    host = host.substring(4)
  }

  ctx.param.starPath = `${host}/${ctx.param.starPath}`

  await next()
}, {group: rse.routeGroup})

rse.init(app)

app.get('/', async ctx => {
  ctx.send('success')
})

app.run(80)
